package main

import (
	"errors"
	"fmt"
)

type integer int

func (i integer) Div(m integer) (r integer, err error) {
	if m == 0 {
		return 0, errors.New("divied by 0")
	}

	return i / m, nil
}

type flyer interface {
	fly()
}

type bird struct {
	name string
}

func (b bird) fly() {
	fmt.Println(b.name + " fly")
}

func whatFly(f flyer) {
	f.fly()
}

func main() {
	b := bird{"my bird"}
	whatFly(b)

	//類型断言
	var x interface{}
	var y float32 = 2.9
	x = y

	//ok==false
	if z, ok := x.(string); ok {
		fmt.Println(z)
	}

	switch x.(type) {
	case float32:
		fmt.Println("x is float32")
	case string:
		fmt.Println("x is string")
	default:
		fmt.Println("x is other type")
	}
}
